﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Linq.Mapping;
using ECI.Entities;
using ECI.Entities.Builder;

namespace ECI.LIP.Entities
{
    ///<summary>
    ///[MES_FLOW]
    ///</summary>
    [Serializable]
    [Table(Name = "MES_FLOW")]
    public partial class MesFlow
    {
        ///<summary>
        ///[主键]
        ///</summary>
        [Column(Storage = "GUID")]
        public string Guid { get { return this._Guid; } set { this._Guid = value; if (this.DataModelBegin)AddEnum(MesFlowEnum.Guid); } }
        ///<summary>
        ///[材料编号]
        ///</summary>
        [Column(Storage = "MATERIAL_NO")]
        public string MaterialNo { get { return this._MaterialNo; } set { this._MaterialNo = value; if (this.DataModelBegin)AddEnum(MesFlowEnum.MaterialNo); } }
        ///<summary>
        ///[流程节点]
        ///</summary>
        [Column(Storage = "STEP_ID")]
        public string StepId { get { return this._StepId; } set { this._StepId = value; if (this.DataModelBegin)AddEnum(MesFlowEnum.StepId); } }
        ///<summary>
        ///[备注]
        ///</summary>
        [Column(Storage = "REMARK")]
        public string Remark { get { return this._Remark; } set { this._Remark = value; if (this.DataModelBegin)AddEnum(MesFlowEnum.Remark); } }
        ///<summary>
        ///[创建人]
        ///</summary>
        [Column(Storage = "CREATE_USER")]
        public string CreateUser { get { return this._CreateUser; } set { this._CreateUser = value; if (this.DataModelBegin)AddEnum(MesFlowEnum.CreateUser); } }
        ///<summary>
        ///[创建时间]
        ///</summary>
        [Column(Storage = "CREATE_DATE")]
        public System.Nullable<System.DateTime> CreateDate { get { return this._CreateDate; } set { this._CreateDate = value; if (this.DataModelBegin)AddEnum(MesFlowEnum.CreateDate); } }

        /// <summary>
        /// ????????:???????True?,????????,?????????????????????,???????????????????????????????????
        /// </summary>
        public void StartSetSQLValue()
        {
            this.DataModelBegin = true;
        }

        /// <summary>
        /// ???????
        /// </summary>
        public void EndSetSQLValue()
        {
            this.DataModelBegin = false;
        }

        private bool DataModelBegin;
        public List<MesFlowEnum> ListEnum { get; set; }

        public void AddEnum(MesFlowEnum item)
        {
            if (ListEnum == null) ListEnum = new List<MesFlowEnum>();
            if (!ListEnum.Contains(item))
            {
                ListEnum.Add(item);
            }
        }



        private MesFlowEnum _keyField;
        public MesFlowEnum KeyField { get { return this._keyField; } }

        public void SetKeyField(MesFlowEnum keyField)
        {
            this.HasSetKeyField = true;
            this._keyField = keyField;
        }

        public MesFlow()
        {
        }

        public MesFlow(MesFlowEnum keyField)
        {
            this.HasSetKeyField = true;
            this._keyField = keyField;
        }

        public bool HasSetKeyField { get; set; }

        public MesFlowEnum SortByField { get; set; }

        public SortDirection SortDirection { get; set; }


        public string SQLUpdate
        {
            get { return new SQLBuilder<MesFlow, MesFlowEnum>().Update(this); }
        }

        public string SQLInsert
        {
            get { return new SQLBuilder<MesFlow, MesFlowEnum>().Insert(this); }
        }

        public string SQLDelete
        {
            get { return new SQLBuilder<MesFlow, MesFlowEnum>().Delete(this); }
        }

        public string SQLSelect
        {
            get { return new SQLBuilder<MesFlow, MesFlowEnum>().Select(this); }
        }

        public void SetAllEnum()
        {
            new SQLBuilder<MesFlow, MesFlowEnum>().SetAllEnum(this);
        }

        private DataTable FetchDataTable()
        {
            return FetchDataTable(null);
        }

        private DataTable FetchDataTable(object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<MesFlow, MesFlowEnum>().GetDataTable(this, ts);
        }

        /// <summary>
        /// ???????????????????FetchEntity??????
        /// </summary>
        public bool HasFetchData { get; set; }

        /// <summary>
        /// ??????????????????????FetchEntity??????
        /// </summary>
        public bool NotFetchData { get { return !HasFetchData; } }

        /// <summary>
        /// ??????-???????SQL
        /// </summary>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesFlow FetchEntity()
        {
            return FetchEntity("", null);
        }

        /// <summary>
        /// ??????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesFlow FetchEntity(string sql)
        {
            return FetchEntity(sql, null);
        }

        /// <summary>
        /// ??????-???????SQL
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesFlow FetchEntity(object ts)
        {
            return FetchEntity("", ts);
        }

        /// <summary>
        /// ??????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <param name="ts">????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesFlow FetchEntity(string sql, object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<MesFlow, MesFlowEnum>().GetEntity(sql, this, ts);
        }

        /// <summary>
        /// ?????????-???????SQL
        /// </summary>
        /// <returns>??????</returns>
        public List<MesFlow> FetchEntities()
        {
            return FetchEntities("", null);
        }

        /// <summary>
        ///  ?????????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <returns>??????</returns>		
        public List<MesFlow> FetchEntities(string sql)
        {
            return FetchEntities(sql, null);
        }

        /// <summary>
        /// ?????????-???????SQL
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>??????</returns>
        public List<MesFlow> FetchEntities(object ts)
        {
            return FetchEntities("", ts);
        }

        /// <summary>
        ///  ?????????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <param name="ts">????</param>
        /// <returns>??????</returns>
        public List<MesFlow> FetchEntities(string sql, object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<MesFlow, MesFlowEnum>().GetEntities(sql, this, ts);
        }

        /// <summary>
        /// ?????????????
        /// </summary>
        /// <returns>True???? False??????</returns>
        public bool Exists()
        {
            return Exists(null);
        }

        /// <summary>
        ///  ?????????????
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>True???? False??????</returns>
        public bool Exists(object ts)
        {
            MesFlow item = this.FetchEntity(ts);
            return item.HasFetchData;
        }




    }


    public partial class MesFlow
    {
        private string _Guid = "";
        private string _MaterialNo = "";
        private string _StepId = "";
        private string _Remark = "";
        private string _CreateUser = "";
        private System.Nullable<System.DateTime> _CreateDate;
    }


    public enum MesFlowEnum
    {
        ///<summary>
        ///[主键]
        ///</summary>
        Guid,
        ///<summary>
        ///[材料编号]
        ///</summary>
        MaterialNo,
        ///<summary>
        ///[流程节点]
        ///</summary>
        StepId,
        ///<summary>
        ///[备注]
        ///</summary>
        Remark,
        ///<summary>
        ///[创建人]
        ///</summary>
        CreateUser,
        ///<summary>
        ///[创建时间]
        ///</summary>
        CreateDate
    }
}
